"use strict";

/**
 * @ngdoc function
 * @name jgappApp.controller:FinanceChoosecontactCtrl
 * @description
 * # FinanceChoosecontactCtrl
 * Controller of the jgappApp
 */
angular
  .module("jgappApp")
  .controller("FinanceChoosecontactCtrl", function(
    $scope,
    Util,
    openApi,
    PagingService
  ) {
    var relModuleObj;
    var param = {};
    // 获取搜索所需参数以及标题信息
    relModuleObj = Util.getDataforsearch();
    param = angular.extend(param, relModuleObj.param || {});
    // 选择后回传的数据
    $scope.choosePeople = function(index) {
      $scope.submit(index);
    };
    $scope.submit = function(index) {
      var filterData;
      if ($scope.taskList.items) {
        // 返回的字段value
        // 如果把需要的key直接挂载在result上面则需要这个方法，否则不用过滤直接返回
        filterData = Util.filterSelectData(
          $scope.taskList.items[index],
          $scope.taskList.valuePropertys,
          relModuleObj.propertyName
        );
        // relModuleObj包含用来回显的值以及返回的内容
        relModuleObj.filterData = filterData;
        Util.savaDataforsearch(relModuleObj);
        Util.goBack();
      }
    };
    $scope.projectName = param.projectName;
    $scope.search = function(projectName) {
      param.projectName = projectName;
      $scope.taskList = new PagingService(openApi.findProjectContract, param);
    };
    $scope.search();
  });
